package org.raymond.iworks.study.netty.official.fundamental.time2;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;

/**
 * @author raymond
 * @version V1.0
 * @Description: 更简化
 */
@Slf4j
public class TimeEncoder2 extends MessageToByteEncoder<UnixTime> {
    @Override
    protected void encode(ChannelHandlerContext ctx, UnixTime msg, ByteBuf out) {
        log.info("2 server encode: {}",msg);
        out.writeInt((int)msg.value());
    }

    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        log.error("encoder2 exceptionCaught...", cause);
        ctx.close();
    }
}
